"""
把对象当做字典操作
"""

class Student:

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __setitem__(self, key, value):
        self.__dict__[key] = value

    def __getitem__(self, key):
        return self.__dict__[key]


if __name__ == '__main__':
    s = Student('聂茹凤',19)
    # print(s.__dict__)
    # print(s.name)

    print(s['name']) # 可以像字典一样获取值



